// utils/fullscreen.js
export const fullscreen = {
  // 进入全屏
  request(element) {
    if (element.requestFullscreen) {
      return element.requestFullscreen();
    } else if (element.webkitRequestFullscreen) {
      return element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
      return element.msRequestFullscreen();
    }
  },
  
  // 退出全屏
  exit() {
    if (document.exitFullscreen) {
      return document.exitFullscreen();
    } else if (document.webkitExitFullscreen) {
      return document.webkitExitFullscreen();
    } else if (document.msExitFullscreen) {
      return document.msExitFullscreen();
    }
  },
  
  // 检查是否全屏
  isFullscreen() {
    return document.fullscreenElement || 
           document.webkitFullscreenElement || 
           document.msFullscreenElement;
  },
  
  // 切换全屏状态
  toggle(element) {
    if (this.isFullscreen()) {
      return this.exit();
    } else {
      return this.request(element);
    }
  },
  
  // 添加事件监听
  onChange(callback) {
    document.addEventListener('fullscreenchange', callback);
    document.addEventListener('webkitfullscreenchange', callback);
    document.addEventListener('msfullscreenchange', callback);
    
    // 返回移除监听的方法
    return () => {
      document.removeEventListener('fullscreenchange', callback);
      document.removeEventListener('webkitfullscreenchange', callback);
      document.removeEventListener('msfullscreenchange', callback);
    };
  }
};